package jpa.Model;

import javax.persistence.*;

/**
 * Created by IntelliJ IDEA.
 * User: Pavlo
 * Date: 30.01.12
 * Time: 13:31
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "Person")
@Access(AccessType.PROPERTY)
public class Person extends ID {

    private Contact contact;

    private PersonType type;

    private District district;


    @OneToOne(optional = true, fetch = FetchType.EAGER)
    @JoinColumn(name = "contacts")
    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }

    @ManyToOne(optional = false)
    @JoinColumn(name = "type", referencedColumnName = "ID")
    public PersonType getType() {
        return type;
    }

    public void setType(PersonType type) {
        this.type = type;
    }

    @OneToOne(cascade = CascadeType.ALL)
    @JoinTable(name = "DistrictSquad",
            joinColumns = @JoinColumn(name = "personID", referencedColumnName = "ID"),
            inverseJoinColumns = @JoinColumn(name = "districtID", referencedColumnName = "ID"))
    public District getDistrict() {
        return district;
    }

    public void setDistrict(District district) {
        this.district = district;
    }
}
